package ch.nostromo.tiffanys.game.chess.pieces;

import java.util.ArrayList;

import ch.nostromo.tiffanys.game.board.Board;
import ch.nostromo.tiffanys.game.board.BoardException;
import ch.nostromo.tiffanys.game.board.BoardTools;
import ch.nostromo.tiffanys.game.move.MoveInput;

public class Queen extends ChessPiece {

  public static ArrayList<MoveInput> getMoveList(Board board, int currentPosition, int owner) throws BoardException {

    ArrayList<MoveInput> result = new ArrayList<MoveInput>();

    int direction = +9;
    int counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = -9;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = +11;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = -11;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = +1;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = -1;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = +10;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    direction = -10;
    counter = checkDirection(board, currentPosition, owner, direction);
    for (int i = 0; i < counter; i++) {
      result.add(new MoveInput(BoardTools.fieldToCoord(currentPosition), BoardTools.fieldToCoord(currentPosition + ((i + 1) * direction))));
    }

    return result;

  }

}